package cn.oowoo.sentinel;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class AlibabaSentinelApplication {

    public static void main(String[] args) {
        sentinelTestRules();
        SpringApplication.run(AlibabaSentinelApplication.class, args);
    }

    public static void sentinelTestRules(){
        new Thread(()->{
            List<FlowRule> rules = new ArrayList<>();
            FlowRule rule = new FlowRule();
            rule.setResource("sentinel.test");
            rule.setCount(1);
            rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
            rules.add(rule);
            FlowRuleManager.loadRules(rules);
        }).run();

    }
}
